find_package(Java COMPONENTS Development)
find_package(JNI REQUIRED)

set(all_sources
    ./cpp/com_automatak_dnp3_impl_ChannelImpl.cpp
    ./cpp/com_automatak_dnp3_impl_ChannelImpl.h
    ./cpp/com_automatak_dnp3_impl_CommandBuilderImpl.cpp
    ./cpp/com_automatak_dnp3_impl_CommandBuilderImpl.h
    ./cpp/com_automatak_dnp3_impl_DatabaseImpl.cpp
    ./cpp/com_automatak_dnp3_impl_DatabaseImpl.h
    ./cpp/com_automatak_dnp3_impl_DNP3ManagerFactory.h
    ./cpp/com_automatak_dnp3_impl_ManagerImpl.cpp
    ./cpp/com_automatak_dnp3_impl_ManagerImpl.h
    ./cpp/com_automatak_dnp3_impl_MasterImpl.cpp
    ./cpp/com_automatak_dnp3_impl_MasterImpl.h
    ./cpp/com_automatak_dnp3_impl_OutstationImpl.cpp
    ./cpp/com_automatak_dnp3_impl_OutstationImpl.h

    ./cpp/adapters/ChannelListenerAdapter.h
    ./cpp/adapters/CommandHandlerAdapter.cpp
    ./cpp/adapters/CommandHandlerAdapter.h
    ./cpp/adapters/ConfigReader.cpp
    ./cpp/adapters/ConfigReader.h
    ./cpp/adapters/Conversions.cpp
    ./cpp/adapters/Conversions.h
    ./cpp/adapters/CString.h
    ./cpp/adapters/GlobalRef.h
    ./cpp/adapters/JNI.cpp
    ./cpp/adapters/JNI.h
    ./cpp/adapters/LocalRef.h
    ./cpp/adapters/LogHandlerAdapter.cpp
    ./cpp/adapters/LogHandlerAdapter.h
    ./cpp/adapters/MasterApplicationAdapter.cpp
    ./cpp/adapters/MasterApplicationAdapter.h
    ./cpp/adapters/OutstationApplicationAdapter.cpp
    ./cpp/adapters/OutstationApplicationAdapter.h
    ./cpp/adapters/SOEHandlerAdapter.cpp
    ./cpp/adapters/SOEHandlerAdapter.h

    ./cpp/jni/JNIWrappers.h
    ./cpp/jni/JCache.cpp
    ./cpp/jni/JCache.h
    ./cpp/jni/JNIAnalogConfig.cpp
    ./cpp/jni/JNIAnalogConfig.h
    ./cpp/jni/JNIAnalogInput.cpp
    ./cpp/jni/JNIAnalogInput.h
    ./cpp/jni/JNIAnalogOutputDouble64.cpp
    ./cpp/jni/JNIAnalogOutputDouble64.h
    ./cpp/jni/JNIAnalogOutputFloat32.cpp
    ./cpp/jni/JNIAnalogOutputFloat32.h
    ./cpp/jni/JNIAnalogOutputInt16.cpp
    ./cpp/jni/JNIAnalogOutputInt16.h
    ./cpp/jni/JNIAnalogOutputInt32.cpp
    ./cpp/jni/JNIAnalogOutputInt32.h
    ./cpp/jni/JNIAnalogOutputStatus.cpp
    ./cpp/jni/JNIAnalogOutputStatus.h
    ./cpp/jni/JNIAnalogOutputStatusConfig.cpp
    ./cpp/jni/JNIAnalogOutputStatusConfig.h
    ./cpp/jni/JNIApplicationIIN.cpp
    ./cpp/jni/JNIApplicationIIN.h
    ./cpp/jni/JNIArrayList.cpp
    ./cpp/jni/JNIArrayList.h
    ./cpp/jni/JNIAssignClassType.cpp
    ./cpp/jni/JNIAssignClassType.h
    ./cpp/jni/JNIBinaryConfig.cpp
    ./cpp/jni/JNIBinaryConfig.h
    ./cpp/jni/JNIBinaryInput.cpp
    ./cpp/jni/JNIBinaryInput.h
    ./cpp/jni/JNIBinaryOutputStatus.cpp
    ./cpp/jni/JNIBinaryOutputStatus.h
    ./cpp/jni/JNIBinaryOutputStatusConfig.cpp
    ./cpp/jni/JNIBinaryOutputStatusConfig.h
    ./cpp/jni/JNIChannelListener.cpp
    ./cpp/jni/JNIChannelListener.h
    ./cpp/jni/JNIChannelState.cpp
    ./cpp/jni/JNIChannelState.h
    ./cpp/jni/JNIChannelStatistics.cpp
    ./cpp/jni/JNIChannelStatistics.h
    ./cpp/jni/JNIClassAssignment.cpp
    ./cpp/jni/JNIClassAssignment.h
    ./cpp/jni/JNIClassField.cpp
    ./cpp/jni/JNIClassField.h
    ./cpp/jni/JNICommandHandler.cpp
    ./cpp/jni/JNICommandHandler.h
    ./cpp/jni/JNICommandHeaders.cpp
    ./cpp/jni/JNICommandHeaders.h
    ./cpp/jni/JNICommandPointResult.cpp
    ./cpp/jni/JNICommandPointResult.h
    ./cpp/jni/JNICommandPointState.cpp
    ./cpp/jni/JNICommandPointState.h
    ./cpp/jni/JNICommandProcessor.cpp
    ./cpp/jni/JNICommandProcessor.h
    ./cpp/jni/JNICommandStatus.cpp
    ./cpp/jni/JNICommandStatus.h
    ./cpp/jni/JNICommandTaskResult.cpp
    ./cpp/jni/JNICommandTaskResult.h
    ./cpp/jni/JNICompletableFuture.cpp
    ./cpp/jni/JNICompletableFuture.h
    ./cpp/jni/JNIControlRelayOutputBlock.cpp
    ./cpp/jni/JNIControlRelayOutputBlock.h
    ./cpp/jni/JNICounter.cpp
    ./cpp/jni/JNICounter.h
    ./cpp/jni/JNICounterConfig.cpp
    ./cpp/jni/JNICounterConfig.h
    ./cpp/jni/JNIDatabase.cpp
    ./cpp/jni/JNIDatabase.h
    ./cpp/jni/JNIDatabaseImpl.cpp
    ./cpp/jni/JNIDatabaseImpl.h
    ./cpp/jni/JNIDNP3Exception.cpp
    ./cpp/jni/JNIDNP3Exception.h
    ./cpp/jni/JNIDatabaseConfig.cpp
    ./cpp/jni/JNIDatabaseConfig.h
    ./cpp/jni/JNIDNPTime.cpp
    ./cpp/jni/JNIDNPTime.h
    ./cpp/jni/JNIDoubleBinaryConfig.cpp
    ./cpp/jni/JNIDoubleBinaryConfig.h
    ./cpp/jni/JNIDoubleBit.cpp
    ./cpp/jni/JNIDoubleBit.h
    ./cpp/jni/JNIDoubleBitBinaryInput.cpp
    ./cpp/jni/JNIDoubleBitBinaryInput.h
    ./cpp/jni/JNIDuration.cpp
    ./cpp/jni/JNIDuration.h
    ./cpp/jni/JNIEntry.cpp
    ./cpp/jni/JNIEntry.h
    ./cpp/jni/JNIEventAnalogOutputStatusVariation.cpp
    ./cpp/jni/JNIEventAnalogOutputStatusVariation.h
    ./cpp/jni/JNIEventAnalogVariation.cpp
    ./cpp/jni/JNIEventAnalogVariation.h
    ./cpp/jni/JNIEventBinaryOutputStatusVariation.cpp
    ./cpp/jni/JNIEventBinaryOutputStatusVariation.h
    ./cpp/jni/JNIEventBinaryVariation.cpp
    ./cpp/jni/JNIEventBinaryVariation.h
    ./cpp/jni/JNIEventBufferConfig.cpp
    ./cpp/jni/JNIEventBufferConfig.h
    ./cpp/jni/JNIEventConfig.cpp
    ./cpp/jni/JNIEventConfig.h
    ./cpp/jni/JNIEventCounterVariation.cpp
    ./cpp/jni/JNIEventCounterVariation.h
    ./cpp/jni/JNIEventDoubleBinaryVariation.cpp
    ./cpp/jni/JNIEventDoubleBinaryVariation.h
    ./cpp/jni/JNIEventFrozenCounterVariation.cpp
    ./cpp/jni/JNIEventFrozenCounterVariation.h
    ./cpp/jni/JNIEventMode.h
    ./cpp/jni/JNIEventMode.cpp
    ./cpp/jni/JNIFlags.cpp
    ./cpp/jni/JNIFlags.h
    ./cpp/jni/JNIFrozenCounter.cpp
    ./cpp/jni/JNIFrozenCounter.h
    ./cpp/jni/JNIFrozenCounterConfig.cpp
    ./cpp/jni/JNIFrozenCounterConfig.h
    ./cpp/jni/JNIGroupVariation.cpp
    ./cpp/jni/JNIGroupVariation.h
    ./cpp/jni/JNIHeader.cpp
    ./cpp/jni/JNIHeader.h
    ./cpp/jni/JNIHeaderInfo.cpp
    ./cpp/jni/JNIHeaderInfo.h
    ./cpp/jni/JNIIINField.cpp
    ./cpp/jni/JNIIINField.h
    ./cpp/jni/JNIIndexedValue.cpp
    ./cpp/jni/JNIIndexedValue.h
    ./cpp/jni/JNIIndexQualifierMode.cpp
    ./cpp/jni/JNIIndexQualifierMode.h
    ./cpp/jni/JNIInteger.cpp
    ./cpp/jni/JNIInteger.h
    ./cpp/jni/JNIIPEndpoint.cpp
    ./cpp/jni/JNIIPEndpoint.h
    ./cpp/jni/JNIIterable.cpp
    ./cpp/jni/JNIIterable.h
    ./cpp/jni/JNIIterator.cpp
    ./cpp/jni/JNIIterator.h
    ./cpp/jni/JNILinkLayerConfig.cpp
    ./cpp/jni/JNILinkLayerConfig.h
    ./cpp/jni/JNILinkLayerStatistics.cpp
    ./cpp/jni/JNILinkLayerStatistics.h
    ./cpp/jni/JNILinkStatistics.cpp
    ./cpp/jni/JNILinkStatistics.h
    ./cpp/jni/JNIList.cpp
    ./cpp/jni/JNIList.h
    ./cpp/jni/JNILogEntry.cpp
    ./cpp/jni/JNILogEntry.h
    ./cpp/jni/JNILogHandler.cpp
    ./cpp/jni/JNILogHandler.h
    ./cpp/jni/JNIMap.cpp
    ./cpp/jni/JNIMap.h
    ./cpp/jni/JNIMasterApplication.cpp
    ./cpp/jni/JNIMasterApplication.h
    ./cpp/jni/JNIMasterConfig.cpp
    ./cpp/jni/JNIMasterConfig.h
    ./cpp/jni/JNIMasterStackConfig.cpp
    ./cpp/jni/JNIMasterStackConfig.h
    ./cpp/jni/JNIMasterTaskType.cpp
    ./cpp/jni/JNIMasterTaskType.h
    ./cpp/jni/JNINumRetries.cpp
    ./cpp/jni/JNINumRetries.h
    ./cpp/jni/JNIObject.cpp
    ./cpp/jni/JNIObject.h
    ./cpp/jni/JNIOperateType.cpp
    ./cpp/jni/JNIOperateType.h
    ./cpp/jni/JNIOperationType.cpp
    ./cpp/jni/JNIOperationType.h
    ./cpp/jni/JNIOutstationApplication.cpp
    ./cpp/jni/JNIOutstationApplication.h
    ./cpp/jni/JNIOutstationConfig.cpp
    ./cpp/jni/JNIOutstationConfig.h
    ./cpp/jni/JNIOutstationStackConfig.cpp
    ./cpp/jni/JNIOutstationStackConfig.h
    ./cpp/jni/JNIParserStatistics.cpp
    ./cpp/jni/JNIParserStatistics.h
    ./cpp/jni/JNIPointClass.cpp
    ./cpp/jni/JNIPointClass.h
    ./cpp/jni/JNIQualifierCode.cpp
    ./cpp/jni/JNIQualifierCode.h
    ./cpp/jni/JNIRange.cpp
    ./cpp/jni/JNIRange.h
    ./cpp/jni/JNIResponseInfo.cpp
    ./cpp/jni/JNIResponseInfo.h
    ./cpp/jni/JNIRestartMode.cpp
    ./cpp/jni/JNIRestartMode.h
    ./cpp/jni/JNISet.h
    ./cpp/jni/JNISet.cpp
    ./cpp/jni/JNISOEHandler.cpp
    ./cpp/jni/JNISOEHandler.h
    ./cpp/jni/JNIStack.cpp
    ./cpp/jni/JNIStack.h
    ./cpp/jni/JNIStackStatistics.cpp
    ./cpp/jni/JNIStackStatistics.h
    ./cpp/jni/JNIStaticAnalogOutputStatusVariation.cpp
    ./cpp/jni/JNIStaticAnalogOutputStatusVariation.h
    ./cpp/jni/JNIStaticAnalogVariation.cpp
    ./cpp/jni/JNIStaticAnalogVariation.h
    ./cpp/jni/JNIStaticBinaryOutputStatusVariation.cpp
    ./cpp/jni/JNIStaticBinaryOutputStatusVariation.h
    ./cpp/jni/JNIStaticBinaryVariation.cpp
    ./cpp/jni/JNIStaticBinaryVariation.h
    ./cpp/jni/JNIStaticCounterVariation.cpp
    ./cpp/jni/JNIStaticCounterVariation.h
    ./cpp/jni/JNIStaticDoubleBinaryVariation.cpp
    ./cpp/jni/JNIStaticDoubleBinaryVariation.h
    ./cpp/jni/JNIStaticFrozenCounterVariation.cpp
    ./cpp/jni/JNIStaticFrozenCounterVariation.h
    ./cpp/jni/JNIStaticTypeBitField.cpp
    ./cpp/jni/JNIStaticTypeBitField.h
    ./cpp/jni/JNITaskCompletion.cpp
    ./cpp/jni/JNITaskCompletion.h
    ./cpp/jni/JNITaskConfig.cpp
    ./cpp/jni/JNITaskConfig.h
    ./cpp/jni/JNITaskId.cpp
    ./cpp/jni/JNITaskId.h
    ./cpp/jni/JNITaskInfo.cpp
    ./cpp/jni/JNITaskInfo.h
    ./cpp/jni/JNITimestampQuality.cpp
    ./cpp/jni/JNITimestampQuality.h
    ./cpp/jni/JNITimeSyncMode.cpp
    ./cpp/jni/JNITimeSyncMode.h
    ./cpp/jni/JNITLSConfig.cpp
    ./cpp/jni/JNITLSConfig.h
    ./cpp/jni/JNITransportStatistics.cpp
    ./cpp/jni/JNITransportStatistics.h
    ./cpp/jni/JNITripCloseCode.cpp
    ./cpp/jni/JNITripCloseCode.h
)

source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${all_sources})

# explicitly build a shared library, it can't be consumed by the JVM as a static library
add_library(opendnp3java SHARED ${all_sources})
target_compile_features(opendnp3java PUBLIC cxx_std_14)
target_link_libraries(opendnp3java PUBLIC opendnp3)
target_include_directories(opendnp3java PRIVATE ${JNI_INCLUDE_DIRS})
set_target_properties(opendnp3java PROPERTIES FOLDER java)
install(TARGETS opendnp3java
    RUNTIME DESTINATION bin
    LIBRARY DESTINATION lib
)
